<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="css/Site.css" />
		<link rel="stylesheet" href="css/zy.all.css" />
		<link rel="stylesheet" href="css/font-awesome.min.css" />
		<link rel="stylesheet" href="css/amazeui.min.css" />
		<link rel="stylesheet" href="css/admin.css" />
		<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
		<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
		<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
	</head>

	<body>
		<div class="dvcontent">
			<div>
				<h4 style="color: red;position:absolute;top: 5px;left: 40%;font-size: 140%;z-index: 100;" th:text="${msg}" th:if="${not #strings.isEmpty(msg)}"></h4>
				<!--tab start-->
				<div class="tabs">
					<div class="hd">
						<ul>
							<li class="on" style="box-sizing: initial;-webkit-box-sizing: initial;">预警管理</li>
							<li class="" style="box-sizing: initial;-webkit-box-sizing: initial;">添加预警</li>
						</ul>
					</div>
					<div class="bd">
						<ul style="display: block;padding: 20px;">
							<li>
								<!--分页显示角色信息 start-->
								<div id="dv1">
									<table class="table" id="tbRecord">
										<thead>
											<tr>
												<th>药品编号</th>
												<th>药品名称</th>
												<th>库存情况</th>
												<th>预警数量</th>
												<th>编辑</th>
												<th>删除</th>
											</tr>
										</thead>
										<tbody>
											<tr th:each="info:${infoes}">
												<td th:text="${info.medicine.medicineId}">34</td>
												<td th:text="${info.medicine.name}">阿昔洛韦片</td>
												<td th:text="${info.warning.status}==false?'库存紧张':'库存充足'"></td>
												<td th:text="${info.warning.number}">200</td>
												<td class="edit"><button data-toggle="modal" data-target="#myModal"><i class="icon-edit bigger-120"></i>编辑</button></td>
												<!-- 模态框（Modal） -->
												<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
													<div class="modal-dialog">
														<div class="modal-content">
															<div class="modal-header">
																<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
																	&times;
																</button>
																<div class="modal-title" id="myModalLabel">
																	<h4>预警信息修改</h4>
																	<!--<h5 th:text="${recordInfo.medicine.medicineId}"></h5><h5 th:text="${recordInfo.medicine.name}"></h5><h5 th:text="${recordInfo.inventory.inventory}"></h5>-->
																</div>
															</div>
															<!--<form th:action="'/editInventory?id='+${recordInfo.medicine.medicineId}" method="get">-->

															<div class="modal-body">
																<div class="am-form-group">
																	<label for="name" class="am-u-sm-3 am-form-label">
																		预警数量</label>
																	<div class="am-u-sm-9">
																		<input type="text" required
																			   placeholder="预警数量" name="number" id="number">
																	</div>
																</div>
															</div>
															<div class="modal-footer">
																<button type="button" class="btn btn-default" data-dismiss="modal">关闭
																</button>
																<button type="button" class="btn btn-primary"  onclick="btn_edit(this)" th:data="${info.warning.medicineId}">
																	提交更改
																</button>
															</div>
														</div><!-- /.modal-content -->
													</div><!-- /.modal -->
												</div>
												<td class="delete"><button onclick="btn_delete(this)" th:data="${info.medicine.medicineId}"><i class="icon-trash bigger-120"></i>删除</button></td>
											</tr>
										</tbody>

									</table>
								</div>
								<!--分页显示角色信息 end-->
							</li>
						</ul>
						<ul class="theme-popbod dform" style="display: none;">
							<div class="am-cf admin-main" style="padding-top: 0px;">
								<!-- content start -->

								<div class="am-cf admin-main" style="padding-top: 0px;">
									<!-- content start -->
									<div class="admin-content">
										<div class="admin-content-body">

											<div class="am-g">
												<div class="am-u-sm-12 am-u-md-4 am-u-md-push-8">

												</div>
												<div class="am-u-sm-12 am-u-md-8 am-u-md-pull-4" style="padding-top: 30px;">
													<form class="am-form am-form-horizontal" th:action="@{addWarning}" method="post">

														<!-- <div class="am-form-group">
															<label for="user-email" class="am-u-sm-3 am-form-label">
								分类</label>
															<div class="am-u-sm-9">
																<select name="groupId" required>
																	<option value="">请选择分类</option>

																</select> <small>分类</small>
															</div>
														</div> -->
														<div class="am-form-group">
															<label class="am-u-sm-3 am-form-label">
																药品名称</label>
																<div class="am-u-sm-9">
																	<!-- <select name="groupId" required>
																		<option value="">请选择药品</option>

																	</select> -->
																	 
																	 <input type="text" required placeholder="请输入药品名称 " name="medicine.name" id="tid">
																	 <small>药品</small>
																</div>
															<div id="did" style="display:none; position:absolute;z-index:1000;top:10%;left:99%;background:white; width:188px;font-size: 16px;color:black;border:1px solid #ccc;"></div>
														</div>

														<div class="am-form-group">
															<label for="name" class="am-u-sm-3 am-form-label">
									数量</label>
															<div class="am-u-sm-9">
																<input type="text" id="name" required placeholder="预警数量" name="warning.number">
																<small>预警数量</small>
															</div>
														</div>
														<!--<div class="am-form-group">-->
															<!--<label for="user-intro" class="am-u-sm-3 am-form-label">-->
									<!--备注</label>-->
															<!--<div class="am-u-sm-9">-->
																<!--<textarea class="" rows="5" id="user-intro" name="remark" placeholder="输入备注"></textarea>-->
																<!--<small>250字以内...</small>-->
															<!--</div>-->
														<!--</div>-->
														<div class="am-form-group">
															<div class="am-u-sm-9 am-u-sm-push-3">
																<input type="submit" class="am-btn am-btn-success" value="添加预警" />
															</div>
														</div>
													</form>
												</div>
											</div>
										</div>
										<footer class="admin-content-footer">
											<hr>
											<p class="am-padding-left"></p>
										</footer>
									</div>
									<!-- content end -->
								</div>
								<!--添加 end-->
							</div>
						</ul>
						</div>
					</div>
					<!--tab end-->

				</div>

				<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
				<script src="js/plugs/Jqueryplugs.js" type="text/javascript"></script>
				<script src="js/_layout.js"></script>
				<script src="js/plugs/jquery.SuperSlide.source.js"></script>
				<script>
					var num = 1;
					$(function() {

						$(".tabs").slide({ trigger: "click" });

					});

					var btn_save = function() {
						var pid = $("#RawMaterialsTypePageId  option:selected").val();
						var name = $("#RawMaterialsTypeName").val();
						var desc = $("#RawMaterialsTypeDescription").val();
						var ramark = $("#Ramark").val();
						$.ajax({
							type: "post",
							url: "/RawMaterialsType/AddRawMaterialsType",
							data: { name: name, pid: pid, desc: desc, ramark: ramark },
							success: function(data) {
								if(data > 0) {
									$.jq_Alert({
										message: "添加成功",
										btnOktext: "确认",
										dialogModal: true,
										btnOkClick: function() {
											//$("#RawMaterialsTypeName").val("");
											//$("#RawMaterialsTypeDescription").val("");
											//$("#Ramark").val("");                           
											//page1();
											location.reload();

										}
									});
								}
							}
						});
						alert(t);
					}

                    var btn_edit = function(obj) {
                        var number=$("#number").val();
                        if (number<=50)
                            alert("预警数量不能过小")
						else {
                            var medicine_id=$(obj).attr("data");
                            $.ajax({
                                url:"/editWarning",
                                data:{"medicine_id":medicine_id,"number":number},
                                type:"post",
                                success:function () {
                                    window.location.reload()
                                }
                            })
						}
                    }


                    var btn_delete = function(obj) {
                        var medicine_id=$(obj).attr("data");
                        $.jq_Confirm({
                            message: "您确定要删除吗?",
                            btnOkClick: function() {
                                $.ajax({
                                    url:"/deleteWarning",
                                    data:{"medicine_id":medicine_id},
                                    type:"post",
                                    success:function () {
                                        window.location.reload()
                                    }
                                })
                            }
                        });
                    }
                    $(document).ready(function(){
                        //文本框keyup的时候发送ajax
                        $("#tid").keyup(function(){
                            //获取文本框中的值
                            var $value = $(this).val();
                            // alert($value);
                            //内容为空的时候不发送ajax
                            if($value!=null&&$value!=''){

                                //清空div
                                $("#did").html("");

                                $.ajax({
                                    url:"/ajaxSearch",
                                    data:{"kw":$value},
                                    method:"get",
                                    success:function(d) {
                                        var arr = d.split(",");
                                        //遍历数组
                                        $(arr).each(function () {
                                            //可以将每一个值放入一个div,将其插入到id为did的div
                                            $("#did").append($("<div>" + this + "</div>"));

                                        });
                                        //将div显示
                                        $("#did").show();

                                    }
                                } );
                            }else{
                                //内容为空的时候，将div隐藏
                                $("#did").hide();

                            }
                        });
                    })
				</script>
			</div>
	</body>

</html>